package ro.savatech.pg.flightlog;

import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;


public class Flight {

	private FlightIndexEntry entry;
	private List<Short> alt1Seria;

	public static Flight fromRaw(FlightIndexEntry entry, byte[] rawBytes) {
		Flight flight = new Flight();
		flight.entry = entry;
		flight.alt1Seria = new ArrayList<Short>();

		ByteBuffer buffer = ByteBuffer.wrap(rawBytes);
		buffer.order(ByteOrder.LITTLE_ENDIAN);

		try {
			while (buffer.hasRemaining()) {
				flight.alt1Seria.add(buffer.getShort());
			}
		} catch (BufferUnderflowException e) {
			throw new DecodeException("Could not decode flight.", e);
		}

		return flight;
	}

	public FlightIndexEntry getEntry() {
		return entry;
	}
	
	public List<Short> getAlt1Seria() {
		return alt1Seria;
	}
}
